package com.yx.cloud.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.iot.base.bean.Product;
import com.yx.cloud.Interface.OnItemClickListener;
import com.yx.cloud.R;
import com.yx.cloud.product.ProductConfigConstants;
import com.yx.cloud.utils.RomUtils;

import org.json.JSONObject;

import java.util.List;

public class SelectSeriesAdapter extends RecyclerView.Adapter implements View.OnClickListener {
    private static final String TAG = "SelectSeriesAdapter";
    private Context mContext;
    private String[] mListDataProduct;
    private View view;
    private OnItemClickListener mOnItemClickListener = null;

    public SelectSeriesAdapter(Context context, String[] listDataProduct) {
        mContext = context;
        mListDataProduct = listDataProduct;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        view = LayoutInflater.from(mContext).inflate(R.layout.selectseries_list_item, parent, false);
        SelectSeriesViewHolder ssv = new SelectSeriesViewHolder(view);
        view.setOnClickListener(this);
        return ssv;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewGroup.LayoutParams layoutParams = holder.itemView.getLayoutParams();
        layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;

        String s = mListDataProduct[position];
        if ("X5 Max".equals(s)) {

        } else if ("tmall".equals(s)) {
            ((SelectSeriesViewHolder) holder).mSeriesName.setText("");
            ((SelectSeriesViewHolder) holder).mSeriesType.setText(mContext.getString(R.string.N_SmartHome_Device));
            ((SelectSeriesViewHolder) holder).mSeriesIcon.setImageResource(R.mipmap.tmall_genie_device_icon);
        } else if ("N5".equals(s)) {
            ((SelectSeriesViewHolder) holder).mSeriesName.setText(s);
            ((SelectSeriesViewHolder) holder).mSeriesType.setText(mContext.getString(R.string.N_SweepAndMopRobot));
            ((SelectSeriesViewHolder) holder).mSeriesIcon.setImageResource(R.mipmap.equipment_icon_pic_n5);
        } else if ("U3 Pro".equals(s)) {
            ((SelectSeriesViewHolder) holder).mSeriesName.setText(s);
            ((SelectSeriesViewHolder) holder).mSeriesType.setText(mContext.getString(R.string.N_SweepAndMopRobot));
            ((SelectSeriesViewHolder) holder).mSeriesIcon.setImageResource(R.mipmap.equipment_icon_pic_u3pro);
        } else {
            ((SelectSeriesViewHolder) holder).mSeriesName.setText(s);
            ((SelectSeriesViewHolder) holder).mSeriesType.setText(mContext.getString(R.string.N_SweepAndMopRobot));
            ((SelectSeriesViewHolder) holder).mSeriesIcon.setImageResource(R.mipmap.equipment_icon_pic_x3);
        }

        holder.itemView.setTag(position);
    }

    @Override
    public int getItemCount() {
        return mListDataProduct.length;
    }

    @Override
    public void onClick(View v) {
        if (RomUtils.isFastClick()) {
            return;
        }
        if (mOnItemClickListener != null) {
            mOnItemClickListener.onItemClick(v, (Integer) v.getTag());
        }
    }

    /**
     * Item点击事件方法
     *
     * @param listener
     */
    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }

    class SelectSeriesViewHolder extends RecyclerView.ViewHolder {
        public TextView mSeriesName;
        public TextView mSeriesType;
        public ImageView mSeriesIcon;

        public SelectSeriesViewHolder(View itemView) {
            super(itemView);
            mSeriesName = itemView.findViewById(R.id.tv_seriesName);
            mSeriesType = itemView.findViewById(R.id.tv_seriesType);
            mSeriesIcon = itemView.findViewById(R.id.iv_robotIcon);
        }
    }

}
